package com.dmcb.trade.business.schedule;

import com.dmcb.common.business.utils.ListUtil;
import com.dmcb.trade.business.entities.ArticleUrl;
import com.dmcb.trade.business.mappers.ArticleUrlMapper;
import com.dmcb.trade.controller.DmbInterfaceController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by miting on 2018/12/21
 */
@Component
public class TradeSchedule {


    @Autowired
    private ArticleUrlMapper articleUrlMapper;
    @Autowired
    private DmbInterfaceController dmbInterfaceController;


    @Value("${trade.crawl.status}")
    protected int crawlStatus;


    @Scheduled(cron = "0 0 */5 * * ?")//每隔5个小时执行一次
//    @Scheduled(fixedDelay = 5000, initialDelay = 5000)
    public void start() {
        if (crawlStatus == 1) {
            testLink();
        }
    }

    private void testLink() {
        List<ArticleUrl> linkList = articleUrlMapper.queryList();
        if (ListUtil.isEmpty(linkList)) {
            return;
        }
        for (ArticleUrl articleUrl : linkList) {
            if (articleUrl.getStatus() == 0) {
                continue;
            }
            String link = articleUrl.getLink();
            dmbInterfaceController.getArticleBody(link);
        }
    }

}
